package com.kafka.demo.service.impl;

import com.kafka.demo.VO.ResultVO;
import com.kafka.demo.emun.ResultCode;
import com.kafka.demo.service.CollectService;
import com.kafka.demo.utils.Listener;
import com.kafka.demo.utils.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author: Cyy
 * @Description:
 * @Date:Created in 17:49 2019/3/20
 */
@Service
@Slf4j
public class CollectSeviceImpl implements CollectService {
//    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private KafkaTemplate kafkaTemplate;

    @Value ("${kafka.consumer.topic}")
    private String topic;


    @Override
    public ResultVO kafkaQueryAll(String message, String key) {
        try {
            log.info("kafka的消息={}", message);
            kafkaTemplate.send(topic, key, message);
            log.info("发送kafka成功.");
            return  ResultVOUtil.success(message);
        } catch (Exception e) {
            log.error("发送kafka失败", e);
            return  ResultVOUtil.error(ResultCode.EXCEPTION.getCode(), "发送kafka失败");
        }
    }


}
